#define _CRT_SECURE_NO_WARNINGS
#include<vector>
#include<string>
using namespace std;
class Solution
{
    int dx[4] = { -1,1,0,0 };
    int dy[4] = { 0,0,-1,1 };

    int m, n;
public:
    void solve(vector<vector<char>>& board)
    {
        m = board.size(); n = board[0].size();
        for (int i = 0; i < n; i++)
        {
            if (board[0][i] == 'O')
            {
                board[0][i] = '1';
                dfs(board, 0, i);
            }
            if (board[m - 1][i] == 'O')
            {
                board[m - 1][i] = '1';
                dfs(board, m - 1, i);
            }
        }
        for (int i = 1; i < m - 1; i++)
        {
            if (board[i][0] == 'O')
            {
                board[i][0] = '1';
                dfs(board, i, 0);
            }
            if (board[i][n - 1] == 'O')
            {
                board[i][n - 1] = '1';
                dfs(board, i, n - 1);
            }
        }
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (board[i][j] == '1') board[i][j] = 'O';
                else if (board[i][j] == 'O') board[i][j] = 'X';
            }
        }
    }
    void dfs(vector<vector<char>>& board, int i, int j)
    {
        for (int k = 0; k < 4; k++)
        {
            int x = dx[k] + i;
            int y = dy[k] + j;
            if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'O')
            {
                board[x][y] = '1';
                dfs(board, x, y);
            }
        }
    }
};
int main()
{
    vector<vector<char>> arr = { {'X','X','X','X'},{'X','O','O','X'},{'X','X','O','X'},
        {'X','O','X','X'} };
    Solution().solve(arr);
    return 0;
}